import React, { Component } from 'react'
import { Consumer } from './context'

export default class GrandSon extends Component {
  render () {
    return (
      <div>
        GrandSon
        {/* Consumer中间有一个表达式，表达式中写一个函数，函数的参数就是最顶级组件传递过来的值，
        然后你要渲染什么内容，要通过返回jsx来渲染 */}
        <Consumer>
          {/* {value => {
            return (
              <div>
                get money is {value}
                <p>
                  <button
                    onClick={() => {
                      console.log('---change---', value)
                      value = 300000000
                    }}
                  >
                    change
                  </button>
                </p>
              </div>
            )
          }} */}
          {obj => {
            return (
              <div>
                get money is {obj.money}
                <p>
                  <button
                    onClick={() => {
                      console.log('---change---', obj)
                      obj.callback(3000000000)
                    }}
                  >
                    change
                  </button>
                </p>
              </div>
            )
          }}
        </Consumer>
      </div>
    )
  }
}
